import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { ContactCollectionComponent } from './contactcollection.component';

// #标记  获取子组件的实例对象
@Component({
  selector: 'collection',
  template: `
              <collection-contact [contact]="detail"
                  (click)="collectTheContact()" #collect>
              </collection-contact>
            `
})

// export class CollectionComponent {
//   detail: any = {};
//   collectTheContact() {
//     this.detail.collection === 0 ? this.detail.collection = 1 : this.detail.collection = 0;
//   }
// }

// 使用@ViewChild
export class CollectionComponent implements AfterViewInit {
  @ViewChild(ContactCollectionComponent)
  private contactCollectionComponent: ContactCollectionComponent;

  ngAfterViewInit() {
   console.log('view init');
  }

  collectTheContact() {
    console.log('fu ');
    console.log(this.contactCollectionComponent);
    this.contactCollectionComponent.collectTheContact();
  }
}
